home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / xinetd.2.0.6 / servtab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  2.3 KB  |  123 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: servtab.c,v 5.2 1992/11/10 08:18:25 panos Exp $" ;
  8.  
  9. #include <syslog.h>
  10.  
  11. #include "pset.h"
  12. #include "sio.h"
  13.  
  14. #include "service.h"
  15. #include "state.h"
  16.  
  17. void msg() ;
  18. void out_of_memory() ;
  19.  
  20.  
  21. /*
  22.  * Try to start all services in the specified service table.
  23.  * On exit, all services in that table that were activated will
  24.  * be in state SVC_ACTIVE.
  25.  */
  26. unsigned start_services( services )
  27.     pset_h services ;
  28. {
  29.     psi_h iter ;
  30.     unsigned services_started = 0 ;
  31.     register struct service *sp ;
  32.     char *func = "start_services" ;
  33.  
  34.     iter = psi_create( services ) ;
  35.     if ( iter == NULL )
  36.     {
  37.         out_of_memory( func ) ;
  38.         return( 0 ) ;
  39.     }
  40.  
  41.     for ( sp = SP( psi_start( iter ) ) ; sp ; sp = SP( psi_next( iter ) ) )
  42.     {
  43.         /*
  44.          * We only start inactive services
  45.          */
  46.         if ( sp->state != SVC_NOT_STARTED )
  47.             continue ;
  48.  
  49.         if ( svc_activate( sp ) == FAILED )
  50.         {
  51.             svc_deactivate( sp ) ;
  52.             continue ;
  53.         }
  54.  
  55.         /*
  56.          * descriptors_free can be negative without a descriptor-allocating
  57.          * system call failing because some of the descriptors we reserve
  58.          * are transient
  59.          */
  60.         if ( ps.rws.descriptors_free < 0 )
  61.         {
  62.             msg( LOG_ERR, func,
  63.                 "Service %s disabled because of lack of file descriptors",
  64.                     CONF( sp )->id ) ;
  65.             svc_deactivate( sp ) ;
  66.             continue ;
  67.         }
  68.  
  69.         /*
  70.          * Activation successful; add service to service table
  71.          */
  72.         if ( pset_add( SERVICES( ps ), sp ) == NULL )
  73.         {
  74.             out_of_memory( func ) ;
  75.             svc_deactivate( sp ) ;
  76.             continue ;
  77.         }
  78.  
  79.         SVC_HOLD( sp ) ;
  80.  
  81.         services_started++ ;
  82.  
  83.         if ( debug.on )
  84.             msg( LOG_DEBUG, func, "Started service: %s", CONF( sp )->id ) ;
  85.     }
  86.  
  87.     psi_destroy( iter ) ;
  88.  
  89.     if ( debug.on )
  90.         msg( LOG_DEBUG, func, "mask_max = %d, services_started = %d",
  91.                 ps.rws.mask_max, services_started ) ;
  92.             
  93.     return( services_started ) ;
  94. }
  95.  
  96.  
  97.  
  98. void destroy_services( stab )
  99.     pset_h stab ;
  100. {
  101.     register unsigned u ;
  102.  
  103.     for ( u = 0 ; u < pset_count( stab ) ; u++ )
  104.         svc_free( SP( pset_pointer( stab, u ) ) ) ;
  105.     pset_destroy( stab ) ;
  106. }
  107.  
  108.  
  109.  
  110. void list_services( stab, fd )
  111.     pset_h stab ;
  112.     int fd ;
  113. {
  114.     register unsigned u ;
  115.  
  116.     for ( u = 0 ; u < pset_count( stab ) ; u++ )
  117.     {
  118.         svc_dump( SP( pset_pointer( stab, u ) ), fd ) ;
  119.         Sputchar( fd, '\n' ) ;
  120.     }
  121. }
  122.  
  123.